import CardImages
import os, pygame, math, glob
from pygame.locals import *
from gloss import *

class CardImages:

    cardImages = []
    backImage = None

    def __init__(self):

        colors = ['s', 'c', 'd', 'h']
        values = ['a', '2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k']

        do_borders = True
        do_scale = True

        self.borderImage = pygame.image.load("./card_bord.png")

        path = './mtg/'
        dirList = os.listdir(path)
        for infile in glob.glob( os.path.join(path, '*.jpg') ):
            image = pygame.image.load(infile).convert()
            # With borders
            if do_borders:
#                self.borderImage = pygame.image.load("./card_bord.png")
                image_with_border = self.borderImage
                rect = image.get_rect()
                rect.x += 12
                rect.y += 12
                image_with_border.blit(image, rect)
                if do_scale:
                    image_with_border = pygame.transform.smoothscale(image_with_border, (image_with_border.get_rect().width * 2 / 3, image_with_border.get_rect().height * 2 / 3))
                self.cardImages.append(image_with_border)
            # Without borders
            else:
                if do_scale:
                    image = pygame.transform.smoothscale(image, (image.get_rect().width * 2 / 3, image.get_rect().height * 2 / 3))
                self.cardImages.append(image)
            print "current file is: " + infile

#        for c in colors:
#            for v in values:
#                self.cardImages.append(pygame.image.load("./cards/%s%s.gif" % (v, c)).convert())

        image = pygame.image.load("./mtg/mtgback.jpg")
        if do_borders:
            image_with_border = self.borderImage
            rect = image.get_rect()
            rect.x += 12
            rect.y += 12
            image_with_border.blit(image, rect)
            if do_scale:
                image_with_border = pygame.transform.smoothscale(image_with_border, (image_with_border.get_rect().width * 2 / 3, image_with_border.get_rect().height * 2 / 3))
            self.backImage = image_with_border
        else:
            if do_scale:
                image = pygame.transform.smoothscale(image, (image.get_rect().width * 2 / 3, image.get_rect().height * 2 / 3))
            self.backImage = image

        #colors = ['spade','club','diamond','heart']
        #values = ['1','2','3','4','5','6','7','8','9','10','jack','queen','king']

        #for c in colors:
        #    for v in values:
        #        self.cardImages.append(pygame.image.load("./CardPng/%s_%s.png" % (v,c)))

        #self.backImage = pygame.image.load("./CardPng/back.png")


    def getCard(self, color, value):
        return self.cardImages[(color * 13) + (value - 1)]

    def getCardNbr(self, nbr):
        return self.cardImages[nbr]

    def getBack(self):
        return self.backImage


class CardImagesGL(CardImages):

    def __init__(self):
        CardImages.__init__(self)

        for i in range(len(self.cardImages)):
            self.cardImages[i] = Texture(self.cardImages[i])

        self.backImage = Texture(self.backImage)
